package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.PersonalDao;
import cn.zyzpp.entity.resume.Personal;
import cn.zyzpp.service.resume.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:53
 */
@Service
@CacheConfig(cacheNames = {"PersonalService"})
public class PersonalServiceImpl implements PersonalService {
    @Autowired
    private PersonalDao personalDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Personal personal, int uid) {
        personal.setUid(uid);
        personalDao.save(personal);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        personalDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(Personal personal) {
        Personal personal1 = personalDao.findAllByUid(personal.getUid());
        personal1.updata(personal);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public Personal query(int uid) {
        return personalDao.findAllByUid(uid);
    }
}
